#ifndef SOCKETGLOBAL_H
#define SOCKETGLOBAL_H

#include "../_Global/GlobalClass.h"

//////////////通信信息////////////

//s给c发送的数据
//#define GAME_CLIENT 200





//client与InfoServer交互
#define INFO_SERVER_REQUEST                         1000
#define INFO_SERVER_RESPONSE                        1100


#define INFO_SERVER_CLIENT                          100


//登录信息
#define INFO_SERVER_CLIENT_LOGIN                    10      //后跟用户名和密码
#define INFO_SERVER_CLIENT_LOGIN_SUCCESS            0   //登录成功,后跟32位id
#define INFO_SERVER_CLIENT_LOGIN_FAIL               1   //登录失败,后跟错误代码:-1登录错误,-2重复登陆

//注册,后跟用户名，昵称和密码
#define INFO_SERVER_CLIENT_REGISTER                 12
#define INFO_SERVER_CLIENT_REGISTER_SUCCESS         0   //注册成功
#define INFO_SERVER_CLIENT_REGISTER_FAIL            1   //注册失败

//服务器信息
#define INFO_SERVER_CLIENT_SERVERINFO               14      //服务器信息
#define INFO_SERVER_CLIENT_SERVERINFO_SUCCESS       0   //登录成功,后跟32位id
#define INFO_SERVER_CLIENT_SERVERINFO_FAIL          1   //登录失败,后跟错误代码:-1登录错误,-2重复登陆







//client与GameInfoServer交互
#define GAME_SERVER_REQUEST             2000
#define GAME_SERVER_RESPONSE            2100


#define GAME_SERVER_CLIENT              100


//获取,后跟用户名，昵称和密码
#define GAME_SERVER_CLIENT_GAMEUSERINFO             10          //用户信息
#define GAME_SERVER_CLIENT_GAMEUSERINFO_SUCCESS             0   //成功
#define GAME_SERVER_CLIENT_GAMEUSERINFO_FAIL                1   //失败

//注册,后跟用户名，昵称和密码
#define GAME_SERVER_CLIENT_REGISTERGAMEUSERINFO     15          //用户信息
#define GAME_SERVER_CLIENT_REGISTERGAMEUSERINFO_SUCCESS     0   //成功
#define GAME_SERVER_CLIENT_REGISTERGAMEUSERINFO_FAIL        1   //失败

//设置额外数据
#define GAME_SERVER_CLIENT_SHAREEXTRAGAMEDATA_SET           20      //设置
#define GAME_SERVER_CLIENT_SHAREEXTRAGAMEDATA_SET_SUCCESS       0   //成功
#define GAME_SERVER_CLIENT_SHAREEXTRAGAMEDATA_SET_FAIL          1   //失败

#define GAME_SERVER_CLIENT_DISCONNECT                       30      //断开


//更新积分
#define GAME_SERVER_CLIENT_UPDATESCORE              40         //保存学习信息
#define GAME_SERVER_CLIENT_UPDATESCORE_SUCCESS          0      //成功
#define GAME_SERVER_CLIENT_UPDATESCORE_FAIL             1      //失败

//其他数据操作
#define GAME_SERVER_GETDATA                         50
#define GAME_SERVER_GETDATA_SUCCESS                     0
#define GAME_SERVER_GETDATA_FAIL                        1

#define GAME_SERVER_SETDATA                         55
#define GAME_SERVER_SETDATA_SUCCESS                     0
#define GAME_SERVER_SETDATA_FAIL                        1

#define GAME_SERVER_DELETEDATA                      60
#define GAME_SERVER_DELETEDATA_SUCCESS                  0
#define GAME_SERVER_DELETEDATA_FAIL                     1


#define GAME_SERVER_INSERTDATA                      65
#define GAME_SERVER_INSERTDATA_SUCCESS                  0
#define GAME_SERVER_INSERTDATA_FAIL                     1

#define GAME_SERVER_UPDATEDATA                      70
#define GAME_SERVER_UPDATEDATA_SUCCESS                  0
#define GAME_SERVER_UPDATEDATA_FAIL                     1

#define GAME_SERVER_DBQUERY                         80
#define GAME_SERVER_DBQUERY_SUCCESS                     0
#define GAME_SERVER_DBQUERY_FAIL                        1

#define GAME_SERVER_DBEXEC                          85
#define GAME_SERVER_DBEXEC_SUCCESS                      0
#define GAME_SERVER_DBEXEC_FAIL                         1



#define GAME_SERVER_GROUP                       200


//房间
#define GAME_SERVER_GROUP_CREATE                    10     //创建房间
#define GAME_SERVER_GROUP_CREATE_SUCCESS                0
#define GAME_SERVER_GROUP_CREATE_FAIL                   1

#define GAME_SERVER_GROUP_UPDATE                    15     //[服务器发送]更新房间信息(锁/自动关闭)
#define GAME_SERVER_GROUP_UPDATE_SUCCESS                0
#define GAME_SERVER_GROUP_UPDATE_FAIL                   1

#define GAME_SERVER_GROUP_CLOSE                     20     //关闭群
#define GAME_SERVER_GROUP_CLOSE_SUCCESS                 0     //成功
#define GAME_SERVER_GROUP_CLOSE_FAIL                    1     //失败

//房主
#define GAME_SERVER_GROUP_SETMASTER                 25
#define GAME_SERVER_GROUP_SETMASTER_SUCCESS             0
#define GAME_SERVER_GROUP_SETMASTER_FAIL                1


//加入游戏
#define GAME_SERVER_GROUP_JOINGROUP                 30     //后跟GroupID
#define GAME_SERVER_GROUP_JOINGROUP_SUCCESS             0       //后跟GroupID
#define GAME_SERVER_GROUP_JOINGROUP_FAIL                1       //后跟Err:-1没有找到房间;-2所有房间满;-3房间正在玩;-4已经加入了该房间
//#define GAME_SERVER_GROUP_JOIN_NOROOM           1
//#define GAME_SERVER_GROUP_JOIN_ROOMFULL         2
//#define GAME_SERVER_GROUP_JOIN_HAVEJOINED       3
//#define GAME_SERVER_GROUP_JOIN_NOTWAITING       4
//#define GAME_SERVER_GROUP_JOIN_PASSERR          5

//别人的信息
#define GAME_SERVER_GROUP_OTHERSINFO                35
#define GAME_SERVER_GROUP_OTHERSINFO_MESSAGE            1       //
#define GAME_SERVER_GROUP_OTHERSINFO_JOINGROUP          2       //
#define GAME_SERVER_GROUP_OTHERSINFO_REJOINRUNNINGGROUP        3       //
#define GAME_SERVER_GROUP_OTHERSINFO_DATA               5       //
//#define GAME_SERVER_GROUP_OTHERSINFO_READY      3       //

//退房间
#define GAME_SERVER_GROUP_EXITGROUP                 40
#define GAME_SERVER_GROUP_EXITGROUP_SUCCESS             0
#define GAME_SERVER_GROUP_EXITGROUP_FAIL                1


//客户端给server 准备开始游戏 或 不准备开始游戏(1个参数)
#define GAME_SERVER_GROUP_GETREADY                  45     //[C/S]后跟 是否准备好
#define GAME_SERVER_GROUP_GETREADY_SUCCESS              0       //[S发送]后跟 是否准备好
#define GAME_SERVER_GROUP_GETREADY_FAIL                 1       //[S]后跟 失败代码

//踢人
#define GAME_SERVER_GROUP_KICK                      50     //[C/S发送]后跟 socketID
#define GAME_SERVER_GROUP_KICK_SUCCESS                  0       //[S发送]
#define GAME_SERVER_GROUP_KICK_FAIL                     1       //[S发送]后跟 失败代码

//重新进入房间
#define GAME_SERVER_GROUP_REJOINRUNNINGGROUP               55     //后跟GroupID
#define GAME_SERVER_GROUP_REJOINRUNNINGGROUP_SUCCESS           0       //后跟GroupID
#define GAME_SERVER_GROUP_REJOINRUNNINGGROUP_FAIL              1       //后跟Err:-1没有找到房间;-2所有房间满;-3房间正在玩;-4已经加入了该房间

//释放GroupIndex
#define GAME_SERVER_GROUP_RELEASEGROUPINDEX         60     //后跟GroupID
#define GAME_SERVER_GROUP_RELEASEGROUPINDEX_SUCCESS     0       //后跟GroupID
#define GAME_SERVER_GROUP_RELEASEGROUPINDEX_FAIL        1       //后跟Err:-1没有找到房间;-2所有房间满;-3房间正在玩;-4已经加入了该房间


#define GAME_SERVER_GROUP_MESSAGE                   70     //

#define GAME_SERVER_GROUP_RANDOMNUMBER              85     //随机数

//发送所有房间信息
//#define GAME_SERVER_GROUP_SENDCREATEINFOS       205
#define GAME_SERVER_GROUP_SENDALLGROUPINFOS         90     //后跟每一个group的序号,id,人数,最大玩家数,-1为结束
//#define GAME_SERVER_GROUP_SENDALLGROUPINFOS     205






//s给c们转发的数据
#define GAME_DATA                               3000



//c给s,请求游戏开始(单人不回复,只是改变状态)
#define GAME_DATA_STARTGAME                         100
#define GAME_DATA_STARTGAME_SUCCESS                     0
#define GAME_DATA_STARTGAME_FAIL                        1

//c给s,初始化完毕
#define GAME_DATA_INITOVER                          110

//客户端给server,单人游戏结束,改变状态
#define GAME_DATA_GAMEOVER                          120
//#define GAME_DATA_GAMEOVER_SUCCESS            0
//#define GAME_DATA_GAMEOVER_FAIL               1

//数据
#define GAME_DATA_TRANSFER_DATA                     130          //
#define GAME_DATA_FRAME_DATA                        135          //
#define GAME_DATA_SYNC_DATA                         140          //
#define GAME_DATA_SYNC_ALLDATA                      145          //



//游戏开始.后跟是否为host,玩家ID,玩家数,玩家信息
//#define GAME_DATA_GAMESTART                     101         //后跟玩家座位号,最大玩家数,是否房主,各玩家类型
//游戏结束
//#define GAME_DATA_GAMEOVER                      102         //后跟结束类型



#define GAME_DATA_MAX_LENGTH 8192   //4096



//需要发送的游戏数据
struct _GameData: public __ProducerData
{
    explicit _GameData()
    {
        //memset(this, 0, sizeof(_GameData));
    }
    virtual ~_GameData() Q_DECL_OVERRIDE
    {
    }

    virtual void Release() Q_DECL_OVERRIDE    //数据需要释放
    {
        switch(type)
        {
        /*case GAME_DATA_TRANSFER_XIPAI:
            {
                if(XiPaiData.pData != nullptr)
                    delete[] XiPaiData.pData;
                XiPaiData.pData = nullptr;
            }
            break;
        case GAME_DATA_TRANSFER_CHUPAI:
            {
                if(ChuPaiData.pData != nullptr)
                    delete[] ChuPaiData.pData;
                ChuPaiData.pData = nullptr;
            }
            break;
        case GAME_DATA_TRANSFER_ALLCHOICEDRENWU:
            {
                //if(AllChoicedRenWuData.pWuJiangData != nullptr)
                //    delete AllChoicedRenWuData.pWuJiangData;
                //AllChoicedRenWuData.pWuJiangData = nullptr;
            }
            break;
        case GAME_DATA_TRANSFER_WENTI:
        case GAME_DATA_TRANSFER_ANSWER:
        case GAME_DATA_TRANSFER_RANDOM:
        case GAME_DATA_TRANSFER_CHOICERENWU:
            {
            }
            break;*/
        default:
            break;
        }

    }

    //数据具体类型定义
    union
    {
        //GAME_DATA_TRANSFER_ALLCHOICEDRENWU:
        struct
        {
            qint16 nPlayerCount;    //玩家数
            qint16 nWuJiangCount;   //一个玩家的武将数
            //qint16 *pWuJiangData;    //武将数据
        }AllChoicedRenWuData;


        //GAME_DATA_TRANSFER_XIPAI:
        struct
        {
            qint16  nData;       //存放PaiDuiShu
            qint16  nDataLength;  //data长度
            char    *pData;         //存放PaiDuiID的具体值
        }XiPaiData;


        //GAME_DATA_TRANSFER_CHUPAI:
        struct
        {
            qint16  nData;       //存放 ret值(按钮)
            qint16  nDataLength;  //data长度
            char    *pData;         //step
        }ChuPaiData;


        //GAME_DATA_TRANSFER_WENTI
        //_EnglishWord *WenTiData;
        struct
        {
            qint32 arrayID[4];
            qint16 nAnswer;
        }WenTiData;


        //GAME_DATA_TRANSFER_ANSWER:
        qint16 nAnswer;


        //GAME_DATA_TRANSFER_RANDOM
        qint32 nRandom;

    };


    //检查从网络收到的游戏数据是否合法
    bool CheckGameData()
    {
        //if(this == nullptr)
        //    return false;

        switch(this->type)
        {
        /*case GAME_DATA_TRANSFER_XIPAI:
            if(this->XiPaiData.nDataLength < 0 || this->XiPaiData.nDataLength > GAME_DATA_MAX_LENGTH)
                return false;
            break;
        case GAME_DATA_TRANSFER_CHUPAI:
            if(this->ChuPaiData.nDataLength < 0 || this->ChuPaiData.nDataLength > GAME_DATA_MAX_LENGTH)
                return false;
            break;
        case GAME_DATA_TRANSFER_WENTI:
            break;
        case GAME_DATA_TRANSFER_ANSWER:
            break;
        case GAME_DATA_TRANSFER_RANDOM:
            break;*/
        default:
            return false;
        }
        return true;
    }

};



/*
//武器坐标

//客户端状态
#define GAME_CLIENT_NORMAL 1
#define GAME_CLIENT_LISTEN 10


//发送数据类型
#define GAME_MSG_LOGIN			100		//登录数据
#define	GAME_MSG_LOGIN_SUCCESS	501		//登录成功
#define	GAME_MSG_LOGIN_FAILED	502		//登录失败
#define GAME_MSG_LOGOUT			200		//注销
#define GAME_MSG_LOGINOFF		201		//登录失败(重复登录)

#define GAME_MSG_NEWONEUP		301		//新人登录
#define GAME_MSG_NEWONEDOWN		302		//新人退出

#define GAME_MSG_REQUESTUPLINELIST	400	//请求在线列表

#define GAME_MSG_TRANSFERDATA	500		//传输数据

//#define GAME_MSG_CONNECTTOPLAY	600		//客户端请求连接
#define GAME_MSG_CONNECTREQUEST	601		//服务端转发客户端请求连接
#define GAME_MSG_CONNECTREQUESTSUCCESS	605		//请求连接成功
#define GAME_MSG_CONNECTREQUESTFAILED	606		//请求连接失败
#define GAME_MSG_CONNECTREPLY	607		//请求连接返回

//服务器信息
#define GAME_SERVER_IP		"127.0.0.1"
#define GAME_SERVER_PORT	9753

//定义常数off-------------------------------------------------
#define TIMER		120		//主时钟周期
#define WIDTH		640		//游戏显示区宽
#define HEIGHT		480		//游戏显示区高
#define GX			40		//地图格宽
#define GY			30		//地图格高


//发送的信息
#define	MSG_UI_REFRESH		100
#define MSG_UI_QUESTIONBOX	101



//手牌的相关坐标
#define POKE_CENTER_X 280	//中间X坐标
#define POKE_CENTER_Y0 200	//中间Y0坐标(顶部)
#define POKE_CENTER_Y1 240	//中间Y1坐标(底部)
#define POKE_TOP_Y 100		//顶部Y坐标


*/


#endif // SOCKETGLOBAL_H


